#ifndef PLOTTER_H
#define PLOTTER_H
#include<QWidget>
#include<QVector>
#include<QList>
#include<QMap>
#include<QPixmap>
#include<QToolButton>
#include<QPainter>
#include "plottersettings.h"


class Plotter : public QWidget{
    Q_OBJECT
public:
    Plotter(QWidget* parent = NULL);

public:
    void setPlotterSetttings(PlotterSettings& settingsList);
    void setData(QMap<int, QVector<QPointF>>& datas);

public:
    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;

protected:
    virtual void paintEvent(QPaintEvent *event);
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void resizeEvent(QResizeEvent *event);

private slots:
    void zoomIn();
    void zoomOut();

private:
    void adjustZoomBtnPosition();
    void refreshPixmap();
    void drawGrid(QPainter& painter, QPixmap& pixmap, PlotterSettings& settings);
    void drawCurve(QPainter& painter, QPixmap& pixmap, PlotterSettings& settings);

private:
    /**
     * @brief settingsList 记录各个放大级别的坐标信息
     * 索引越大，代表放大级别越大，索引越小，代表放大级别越小
     */
    QVector<PlotterSettings> settingsList;
    int currentSettingIndex;//当前放大级别在setting中的索引
    QMap<int, QVector<QPointF>> datas;//数据
    QPixmap pixMap;
    //QPainter* painter;
    QToolButton* btnZoomIn;//放大
    QToolButton* btnZoomOut;//缩小
    bool isRubberBandShow;//选择框是否显示出来
    QRectF rubberBandRect;//选择框的范围(放大的选择框)
    const int MARGIN = 50;
};

#endif // PLOTTER_H
